package ace.module.upms.core.impl.controller.rest.rpc.callback;

import ace.cmp.security.oauth2.resource.server.core.annotation.PreAuthorizeIsInternalClient;
import ace.module.common.api.annotation.ApiRemoteImplementPriority;
import ace.module.oauth2.server.api.model.dto.ext.Oauth2AceUserInfoResultDto;
import ace.module.oauth2.server.api.callback.model.input.Oauth2AceAuthorizationCallbackInput;
import ace.module.upms.core.impl.service.UpmsOauth2Service;
import ace.module.upms.oauth2.api.input.UpmsOauth2CallbackUserInfoInput;
import ace.module.upms.oauth2.sdk.core.feign.impl.UpmsOauth2CallbackUserInfoFeign;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Caspar
 */
@PreAuthorizeIsInternalClient
@ApiRemoteImplementPriority
@AllArgsConstructor
@RestController
@RequestMapping(UpmsOauth2CallbackUserInfoFeign.PATH)
public class UpmsOauth2RestUserInfoCallbackRpcController
    implements UpmsOauth2CallbackUserInfoFeign {
  private final UpmsOauth2Service upmsOAuth2Service;

  @Override
  public Oauth2AceUserInfoResultDto getUserInfo(UpmsOauth2CallbackUserInfoInput input) {
    Long upmsAppId = input.getUpmsAppId();
    Oauth2AceAuthorizationCallbackInput oauth2RestRequest = input.getOauth2RestRequest();
    return upmsOAuth2Service.getOauth2UserInfo(upmsAppId, oauth2RestRequest);
  }
}
